package org.dairy.farms.dao.hibernate;

import org.dairy.farms.dao.FarmDAO;
import org.dairy.farms.dao.generic.AbstractDAOImpl;
import org.dairy.farms.model.CheckupType;
import org.dairy.farms.model.Farm;
import org.dairy.farms.model.Person;
import org.hibernate.Criteria;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: gduggira
 * Date: Jun 13, 2011
 * Time: 3:23:20 PM
 */
@Repository(value = "farmDao")
public class FarmDAOImpl extends AbstractDAOImpl<Farm, Long> implements FarmDAO {
    @Override
    public List<Farm> loadAll() {
        return basePersistence.loadAll(Farm.class);
    }

    @Override
    public List<Farm> loadUserFarms(Long personID) {
        Criteria criteria = basePersistence.getSession().createCriteria(Farm.class);
        criteria.createCriteria("persons").add(Restrictions.eq("id",personID));
        return criteria.list();
    }

}
